package com.example.demo.config;

import com.example.demo.constant.RequestUrl;
import com.example.demo.interceptor.TokenInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 *@Description 拦截器配置
 *@Author Levi
 *@Date 2019/4/24-9:57
*/
@Configuration
public class InterceptorConfig implements WebMvcConfigurer {
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        String[] excludePaths = {RequestUrl.API+RequestUrl.LOGIN};
        registry.addInterceptor(tokenInterceptor()).
                addPathPatterns("/**").
                excludePathPatterns(excludePaths).
                excludePathPatterns("/swagger-resources/**", "/webjars/**", "/v2/**", "/swagger-ui.html/**");//swagger
    }

    @Bean
    public TokenInterceptor tokenInterceptor(){
        return new TokenInterceptor();
    }

}
